using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ProjectileImpactEffectBase:MonoBehaviour {

	static EventSubscriber<ProjectileEventArgs> DestroySubscriber = new EventSubscriber<ProjectileEventArgs>();
	static EventSubscriber<ProjectileHitEventArgs> HitMobSubscriber = new EventSubscriber<ProjectileHitEventArgs>();
	static EventSubscriber<ProjectileHitEventArgs> HitWallSubscriber = new EventSubscriber<ProjectileHitEventArgs>();
	static ProjectileImpactEffectBase() {
		Projectile.ProjectileHitMob+=HitMobSubscriber.TargetEventHandler;
		Projectile.ProjectileHitWall+=HitWallSubscriber.TargetEventHandler;
		Projectile.ProjectileDestroy+=DestroySubscriber.TargetEventHandler;
	}

	void Start() {
		projectile=GetComponent<Projectile>();
		DestroySubscriber.SubscribeSingle(projectile,ProjectileDestroyEventHandler);
		HitMobSubscriber.SubscribeSingle(projectile,ProjectileHitMobEventHandler);
		HitWallSubscriber.SubscribeSingle(projectile,ProjectileHitWallEventHandler);
	}

	void OnDestroy() {
		DestroySubscriber.UnsubscribeSingle(projectile,ProjectileDestroyEventHandler);
		HitMobSubscriber.UnsubscribeSingle(projectile,ProjectileHitMobEventHandler);
		HitWallSubscriber.UnsubscribeSingle(projectile,ProjectileHitWallEventHandler);
	}

	Projectile projectile;

	protected virtual void ProjectileDestroyEventHandler(object sender,ProjectileEventArgs e) { }
	protected virtual void ProjectileHitWallEventHandler(object sender,ProjectileHitEventArgs e) { }
	protected virtual void ProjectileHitMobEventHandler(object sender,ProjectileHitEventArgs e) { }

	protected bool IfReactProjectileEvent(object _sender,ProjectileHitEventArgs e) {
		Projectile sender = _sender as Projectile;
		if(!sender) return false;
		if(sender.gameObject!=gameObject) return false;
		return true;
	}

}
